<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
	<th:block th:include="include :: header('商品库')" />
	<th:block th:include="include :: businessCSS" />
	<style>
        .main-content{position: relative;}
        .topbtns{position:fixed;top: 0;width: 100%;z-index: 9999;background-color: #fff;}
		.preservationBtn{padding: 10px;margin: 0;position: fixed;top: 0;z-index: 9999;background: #fff;width: 100%;}
		.preservationBtn input{font-size: 16px;background-color: rgb(80, 138, 238);color: #fff;border: none;padding: 5px 30px;border-radius: 5px;cursor: pointer;}
		/* .layui-border-box{height: 350px !important;}
		.layui-table-body{height: 240px !important;} */
		.layui-table-tool-temp{padding-right: 30px;}
        .getDetailUpload,.getDetailUpload2{cursor: pointer;}
        .layui-table-tool-self{display: none;}
		textarea{width: 100%;border-color: #ddd;}

        .tablebody{background-color: #fff;padding: 20px;margin-right: 15px;}
		.tablebody input{display: inline;width: 100%;border: none;}
		.tablebody table{width: 100%;}
		.tablebody th,.tablebody td{border:solid 1px #ddd;padding:10px;font-size:14px;text-align: center;min-width: 80px;}


	</style>
</head>
<body class="no-skin">
<div class="main-container" id="main-container">
	<div class="main-content">
	<form class="layui-form head-form">
        <div class="topbtns"><th:block th:include="include :: business_btn" /></div>
	    <div class="north" style="background-color: #fff;margin-top: 55px;">
			<div class="forminput"></div>
    	</div>
        <div style="width: 100%;height: 10px;background: #f6f6f6;"></div>

        <div class="tablebody">
            <table class="zjtable">
                <thead>
                    <tr>
                        <th>子件编码</th><th>子件名称</th><th>子件数量</th><th>所需数量</th><th>货位编码</th>
                        <th>库区</th><th>所在仓库</th><th>库存数量</th><th>需求数量</th>
                    </tr>
                </thead>
                <tbody class="tbody bodyadd"></tbody>
            </table>
        </div>

        <th:block th:include="include :: pageFooter" /> 
    </form>
	</div>
</div>

<th:block th:include="include :: footer" />
<th:block th:include="include :: businessJS" />
<th:block th:include="include :: inlineJS" />


<script th:inline="javascript">
	/*<![CDATA[*/
	var prefix = ctx + "storage/manualassembly",
    	prefix2 = ctx + "base/company";

	var fields = [[${fields}]];
    var fieldsList = [[${fieldsList}]];
	var fieldsHiddenList = [[${fieldsHiddenList}]];
	var moduleTable = [[${moduleTable}]];
	var enableEdit = [[${enableEdit}]];
	var manualAssemblyList = [[${manualAssemblyList}]];
    //母件表格基础信息
	var gridColumns = [[${gridColumns}]];

	var $,layer,form,table,nid,noTable;
    layui.use(['laydate','form','layer','jquery','util','element','upload','table'], function () {
        $ = layui.$,layer = layui.layer,form = layui.form,laydate = layui.laydate,util = layui.util,element=layui.element,upload = layui.upload,table = layui.table;
        beforeInit();//表单初始化之前的动作集合
		//初始化操作
		headcom3()
        assemblyhead()
        nid=$('#nid').val()

        window.first=function(manualAssemblyList){
            var str=''
            if(manualAssemblyList.length>0){
                for(var i=0;i<manualAssemblyList.length;i++){
		        	for(var j=0;j<manualAssemblyList[i].manualAssemblyList.length;j++){
                        if(j==0){
		        			str+=`<tr>
		        		    	<td class="fsCode" rowspan="${manualAssemblyList[i].manualAssemblyList.length}">${manualAssemblyList[i].sCode ?manualAssemblyList[i].sCode :''}</td>
		        		    	<td class="fsName" rowspan="${manualAssemblyList[i].manualAssemblyList.length}">${manualAssemblyList[i].sName ?manualAssemblyList[i].sName :''}</td>
		        		    	<td class="fsNum" rowspan="${manualAssemblyList[i].manualAssemblyList.length}">${manualAssemblyList[i].sNum}</td>
		        		    	<td class="ftotalDemand" rowspan="${manualAssemblyList[i].manualAssemblyList.length}">${manualAssemblyList[i].totalDemand}</td>

		        		    	<td class='goodsAllocation'>${manualAssemblyList[i].manualAssemblyList[j].goodsAllocation ?manualAssemblyList[i].manualAssemblyList[j].goodsAllocation :''}</td>
		        		    	<td class='goodsArea'>${manualAssemblyList[i].manualAssemblyList[j].goodsArea ?manualAssemblyList[i].manualAssemblyList[j].goodsArea :''}</td>
		        		    	<td class='warehouseAddress'>${manualAssemblyList[i].manualAssemblyList[j].warehouseAddress ?manualAssemblyList[i].manualAssemblyList[j].warehouseAddress :''}</td>
		        		    	<td class='stockNum'>${manualAssemblyList[i].manualAssemblyList[j].stockNum ?manualAssemblyList[i].manualAssemblyList[j].stockNum :''}</td>
		        		    	<td><input type="number" class='quantityRequired' value='${manualAssemblyList[i].manualAssemblyList[j].quantityRequired}'></td>
    
		        				<input type="hidden" class='guid' value='${manualAssemblyList[i].manualAssemblyList[j].guid}'>
		        				<input type="hidden" class='sCode' value='${manualAssemblyList[i].sCode}'>
		        				<input type="hidden" class='sName' value='${manualAssemblyList[i].sName}'>
		        				<input type="hidden" class='sNum' value='${manualAssemblyList[i].sNum}'>
		        				<input type="hidden" class='totalDemand' value='${manualAssemblyList[i].totalDemand}'>
		        				<input type="hidden" class='vGsMc' value='${manualAssemblyList[i].manualAssemblyList[j].vGsMc}'>
		        				<input type="hidden" class='vGsJc' value='${manualAssemblyList[i].manualAssemblyList[j].vGsJc}'>
		        				<input type="hidden" class='vGsBm' value='${manualAssemblyList[i].manualAssemblyList[j].vGsBm}'>
		        				<input type="hidden" class='rkGuid' value='${manualAssemblyList[i].manualAssemblyList[j].rkGuid}'>
		        				<input type="hidden" class='rkBid' value='${manualAssemblyList[i].manualAssemblyList[j].rkBid}'>
		        				<input type="hidden" class='vHw' value='${manualAssemblyList[i].manualAssemblyList[j].vHw}'>
		        				<input type="hidden" class='vKq' value='${manualAssemblyList[i].manualAssemblyList[j].vKq}'>
		        				<input type="hidden" class='gDepot' value='${manualAssemblyList[i].manualAssemblyList[j].gDepot}'>
		        		    </tr>`
		        		}else{
		        			str+=`<tr>
		        		    	<td class='goodsAllocation'>${manualAssemblyList[i].manualAssemblyList[j].goodsAllocation ?manualAssemblyList[i].manualAssemblyList[j].goodsAllocation :''}</td>
		        		    	<td class='goodsArea'>${manualAssemblyList[i].manualAssemblyList[j].goodsArea ?manualAssemblyList[i].manualAssemblyList[j].goodsArea :''}</td>
		        		    	<td class='warehouseAddress'>${manualAssemblyList[i].manualAssemblyList[j].warehouseAddress ?manualAssemblyList[i].manualAssemblyList[j].warehouseAddress :''}</td>
		        		    	<td class='stockNum'>${manualAssemblyList[i].manualAssemblyList[j].stockNum ?manualAssemblyList[i].manualAssemblyList[j].stockNum :''}</td>
		        		    	<td><input type="number" class='quantityRequired' value='${manualAssemblyList[i].manualAssemblyList[j].quantityRequired}'></td>
		        				<input type="hidden" class='guid' value='${manualAssemblyList[i].manualAssemblyList[j].guid}'>
		        				<input type="hidden" class='sCode' value='${manualAssemblyList[i].sCode}'>
		        				<input type="hidden" class='sName' value='${manualAssemblyList[i].sName}'>
		        				<input type="hidden" class='sNum' value='${manualAssemblyList[i].sNum}'>
                                <input type="hidden" class='totalDemand' value='${manualAssemblyList[i].totalDemand}'>
		        				<input type="hidden" class='vGsMc' value='${manualAssemblyList[i].manualAssemblyList[j].vGsMc}'>
                                <input type="hidden" class='vGsJc' value='${manualAssemblyList[i].manualAssemblyList[j].vGsJc}'>
                                <input type="hidden" class='vGsBm' value='${manualAssemblyList[i].manualAssemblyList[j].vGsBm}'>
                                <input type="hidden" class='rkGuid' value='${manualAssemblyList[i].manualAssemblyList[j].rkGuid}'>
                                <input type="hidden" class='rkBid' value='${manualAssemblyList[i].manualAssemblyList[j].rkBid}'>
                                <input type="hidden" class='vHw' value='${manualAssemblyList[i].manualAssemblyList[j].vHw}'>
                                <input type="hidden" class='vKq' value='${manualAssemblyList[i].manualAssemblyList[j].vKq}'>
                                <input type="hidden" class='gDepot' value='${manualAssemblyList[i].manualAssemblyList[j].gDepot}'>
		        		    </tr>`
		        		}
		        	}
                    
		        }
            }else{
                str+=`<tr><td colspan="10">暂无数据</td></tr>`
            }
            // console.log(str,111)
		    $('.bodyadd').html(str)
        }

        $(document).ready(function(){
		    first(manualAssemblyList)
            $('.tp-save').attr('onclick',"tpBtnClick('sgzzadd')")
	    })

        $('body').on('blur','#actualNum',function(){
            var actualNum=$(this).val()
            $('.tbody tr').each(function (i) {
                $(this).children('.totalDemand').val(+actualNum*(+$(this).children('.sNum').val()))
                $(this).children('.ftotalDemand').text(+actualNum*(+$(this).children('.sNum').val()))
            })
        });

        $.get("/storage/manualassembly/listbynid?nid="+nid,function(res){
 	    	noTable=res.data;
	    });


    });

    function getMoreAfter(fieldsList,fields,tindex,fieldName,fieldSearchType,isSearch,isLayer,datas){//弹出框赋值回调
        if(fields=='productID'){
            var goodsid=$('#productID').val()
            $.get('/storage/manualassembly/getManualAssemblyList',{productCode:goodsid},function(res){
                console.log("res",res)
                for (let i = 0; i < res.data.length; i++) {
                    for (let j = 0; j < res.data[i].manualAssemblyList.length; j++) {
                        res.data[i].manualAssemblyList[j].guid = ''
                    }
                }
                first(res.data)
		    })
        }
    }
    

</script>

</body>
</html>